/*
 * PorosityTimeDerivativeKernel.C
 *
 *  Created on: 2017年8月29日
 *      Author: liuxiao
 */

/*
 * PyrolysisHeatSourceKernal.C
 *
 *  Created on: 2017年7月24日
 *      Author: liuxiao
 */

#include "PorosityTimeDerivativeKernel.h"
registerMooseObject("TrilobitaApp", PorosityTimeDerivativeKernel);
template<>
InputParameters validParams<PorosityTimeDerivativeKernel>()
{
  InputParameters params = validParams<Kernel>();
  params.addClassDescription("Compute Porosity TimeDerivative ");
  params.addRequiredCoupledVar("temperature", "Coupled Temperature");
  return params;
}

PorosityTimeDerivativeKernel::PorosityTimeDerivativeKernel(const InputParameters & parameters) :
  Kernel(parameters),
  _R(getMaterialProperty<Real>("gas_constant")),
  _temperature(coupledValue("temperature")),
  _drhos_dt(getMaterialProperty<Real>("drhos_dt")),
  _porosity_v(getMaterialProperty<Real>("porosity_v")),
  _porosity_c(getMaterialProperty<Real>("porosity_c")),
  _porosity(getMaterialProperty<Real>("porosity")),
  _rhov(getMaterialProperty<Real>("rhov")),
  _rhoc(getMaterialProperty<Real>("rhoc")),
  _rhos(getMaterialProperty<Real>("solid_density"))
{

}

Real PorosityTimeDerivativeKernel::computeQpResidual()
{
//	std::cout << _k[_qp] <<std::endl;

  if((_rhov[_qp]-_rhoc[_qp])<0.0000001)
  {
	  return 0;
  }
  else
  {
	  Real r(0);
	  Real coff = (_porosity_v[_qp]-_porosity_c[_qp])/(_rhov[_qp]-_rhoc[_qp]);;
	  r = (_u[_qp]/_R[_qp]/(_temperature[_qp]+1e-16))*coff*_drhos_dt[_qp] * _test[_i][_qp];
	  return r;
  }

}

Real PorosityTimeDerivativeKernel::computeQpJacobian()
{

	if((_rhov[_qp]-_rhoc[_qp])<0.0000001)
	{
		return 0;
	}
	else
	{
		Real jac(0);
		Real coff = (_porosity_v[_qp]-_porosity_c[_qp])/(_rhov[_qp]-_rhoc[_qp]);
		jac = (1.0/_R[_qp]/(_temperature[_qp]+1e-16))*coff*_drhos_dt[_qp]*_phi[_j][_qp] *_test[_i][_qp];
		return jac;
	}
}







